package client;

import java.io.IOException;

import util.SMSUtil;
import view.ViewManager;
import controller.LoginController;

public class SMSClient {

	public static void main(String[] args) throws IOException {

		String uName = null;
		String pass = null;
		String request = null;
		String choice1 = "Y";
		String choice2 = "Y";
		int index = 1;
		while(choice2.trim().equalsIgnoreCase("y")){
			System.out.println("Please enter Username:");
			uName = SMSUtil.getUserInput();
			System.out.println("Please enter Password:");
			pass = SMSUtil.getUserInput();
			LoginController lc = new LoginController();
			lc.setUserName(uName.trim());
			lc.setPassword(pass.trim());	
			choice1 = "y";
			if (lc.authenticate() == true) {				
				while (choice1.trim().equalsIgnoreCase("y")) {
					/*index = 1;
					List<String> userActions = lc.getUserActions();
					System.out.println("Please select an action to be performed:");
					for (String action : userActions) {
						System.out.println(index + " " + action);
						index++;
					}
	
				    request = SMSUtil.getUserInput();
				    if(lc.isAuthorized(request)){
				    	RequestDispatcher requestDispatch = new RequestDispatcher(request.trim(), lc.getUser());
						requestDispatch.processRequest();
				    }else{
				    	System.out.println("****You are not authorized to perform this action****");
				    }*/
					
					ViewManager manager = new ViewManager(lc.getUser());
					manager.displayView();
						
					System.out.println("Do you wish to continue?(Y/N)");
					choice1 = SMSUtil.getUserInput();
				
	
				}
			} else {
				System.out.println("Authentication failed. Incorrect username/password.");
				System.out.println("Do you wish to continue?(Y/N)");
				choice2 = SMSUtil.getUserInput();
	
			}
		}
		
		System.out.println("Thank you for using our Sales Management System");

	}
}
